﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace UI.Admin.Log
{
    /// <summary>
    /// AjaxAction 的摘要说明
    /// </summary>
    public class AjaxAction : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            // 验证
            //string auth = Utility.Authorization.Check(HttpContext.Current.Session["role"], "LogAdmin", "");
            //if (auth != "ACCEPT")
            //{
               // return;
           // }

            context.Response.ContentType = "text/plain";

            string dowhat = context.Request["dowhat"];
            if (dowhat == null) dowhat = "";

             // 操作用户及IP
            string UserName = "test";//((Models.User)(HttpContext.Current.Session["user"])).Name;
            string UserIP = "1314";//context.Request.ServerVariables["LOCAl_ADDR"];

            #region 删除日志
            if (dowhat == "delete_log")
            {
                string ID = context.Request["ID"];

                if (BLL.Delete.DeleteLog(ID) > 0)
                {
                    // Log
                    context.Response.Write("success");
                }
                else
                {
                    // Log
                    context.Response.Write("failed");
                }
                context.Response.End();
                return;
            }
            #endregion

            #region 批量删除日志
            if (dowhat == "deletes_log")
            {
                string days = context.Request["days"];

                if (BLL.Delete.DeleteSomeLog(days)>0)
                {
                    // Log
                    BLL.Create.CreateLogRecord(UserName, UserIP, "批量删除了" + days + "天前的记录");
                    context.Response.Write("success");
                }
                else
                {
                    // Log
                    context.Response.Write("failed");
                }
                context.Response.End();
                return;
            }
            #endregion

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}